<template>
    <div class="edit-device">
        <index-breadcrumb :breadcrumb-list="breadcrumbList" :isShow="true"></index-breadcrumb>
        <edit-project :operation-list="operationList" :is-show="showStatus" @changeTitle="changeTitle"></edit-project>
    </div>
</template>

<script>
import EditProject from "./includes/EditProject";

export default {
    name: "EditProjectName",
    components: {
        EditProject
    },
    data() {
        return {
            deviceData: null,
            operationList: [],
            showStatus: true,
            breadcrumbList: [
                {
                    title: "项目管理",
                    path: "/project"
                },
                {
                    title: "查看"
                }
            ]
        };
    },
    activated() {
        this.breadcrumbList = [
            {
                title: "项目管理",
                path: "/project"
            },
            {
                title: "查看"
            }
        ]
    },
    created() {
        this.getOperationList();
        this.breadcrumbList = [
            {
                title: "项目管理",
                path: "/project"
            },
            {
                title: "查看"
            }
        ]
    },
    methods: {
        changeTitle(val){
            if(val){
                this.breadcrumbList = [
                    {
                        title: "项目管理",
                        path: "/project"
                    },
                    {
                        title: "编辑"
                    }
                ]
            }
        },
        backShow() {
            this.showStatus = true
        },
        getOperationList() {
            this.$store.state.permissionList.forEach(item => {
                const [itemName] = item.permission.split(":");
                if (itemName === "project") {
                    this.operationList = item.list.map(listItem => {
                        return listItem.permission.split(":")[1];
                    });
                }
                if (itemName === "permission") {
                    item.list.some(listItem => {
                        const listItemType = listItem.permission.split(":")[1];
                        if (listItemType === "edit") {
                            this.operationList.push("permission:edit");
                            return true;
                        }
                        return false;
                    });
                }
            });
        }
    }
};
</script>

<style lang="sass" scoped>

</style>
